# 示例 4: 使用线程池
from concurrent.futures import ThreadPoolExecutor

def print_numbers(n):
    for i in range(n):
        print(i)

# 创建一个线程池，最多允许5个线程同时运行
with ThreadPoolExecutor(max_workers=5) as executor:
    # 提交任务到线程池
    futures = [executor.submit(print_numbers, 5) for _ in range(10)]

    # 等待所有任务完成（可选）
    for future in futures:
        future.result()

print("All tasks have finished execution.")

























